//
//  ViewController.m
//  CharlesMVX
//
//  Created by Charles on 2020/3/11.
//  Copyright © 2020 Charles. All rights reserved.
//

#import "ViewController.h"
#import "MVCUserViewController.h"
#import "MVCInfoViewController.h"
#import "MVPUserViewController.h"
#import "MVVMUserViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    // MVC
    UIView *mvcView = [[UIView alloc]initWithFrame:CGRectMake(0, 64 + 20, self.view.bounds.size.width, 200)];
    mvcView.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:mvcView];
    
    UILabel *mvcTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,40, self.view.bounds.size.width, 30)];
    mvcTitleLabel.textAlignment = NSTextAlignmentCenter;
    mvcTitleLabel.text = @"MVC";
    [mvcView addSubview:mvcTitleLabel];
    
    UIButton *mvcUserInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mvcUserInfoBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 150)/2,CGRectGetMaxY(mvcTitleLabel.frame) + 20, 150, 30);
    [mvcUserInfoBtn setTitle:@"查看用户信息" forState:UIControlStateNormal];
    mvcUserInfoBtn.tag = 124;
    [mvcUserInfoBtn addTarget:self action:@selector(mvcLookUserInfo:) forControlEvents:UIControlEventTouchUpInside];
    [mvcView addSubview:mvcUserInfoBtn];
    
    UIButton *mvcSelfUserInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mvcSelfUserInfoBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 150)/2, CGRectGetMaxY(mvcUserInfoBtn.frame) + 20, 150, 30);
    [mvcSelfUserInfoBtn setTitle:@"查看个人信息" forState:UIControlStateNormal];
    mvcSelfUserInfoBtn.tag = 123;
    [mvcSelfUserInfoBtn addTarget:self action:@selector(mvcLookUserInfo:) forControlEvents:UIControlEventTouchUpInside];
    [mvcView addSubview:mvcSelfUserInfoBtn];
    
    
    // MVP
    UIView *mvpView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(mvcView.frame), self.view.bounds.size.width, 200)];
    mvpView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:mvpView];
    
    UILabel *mvpTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,40, self.view.bounds.size.width, 30)];
    mvpTitleLabel.textAlignment = NSTextAlignmentCenter;
    mvpTitleLabel.text = @"MVP";
    [mvpView addSubview:mvpTitleLabel];
    
    UIButton *mvpUserInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mvpUserInfoBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 150)/2,CGRectGetMaxY(mvpTitleLabel.frame) + 20, 150, 30);
    [mvpUserInfoBtn setTitle:@"查看个人信息" forState:UIControlStateNormal];
    [mvpUserInfoBtn addTarget:self action:@selector(mvpLookUserInfo) forControlEvents:UIControlEventTouchUpInside];
    [mvpView addSubview:mvpUserInfoBtn];
    
    
    // MVVM
    
    UIView *mvvmView = [[UIView alloc]initWithFrame:CGRectMake(0,CGRectGetMaxY(mvpView.frame), self.view.bounds.size.width, 200)];
    mvvmView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:mvvmView];
    
    UILabel *mvvmTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,40, self.view.bounds.size.width, 30)];
    mvvmTitleLabel.textAlignment = NSTextAlignmentCenter;
    mvvmTitleLabel.text = @"MVVM";
    [mvvmView addSubview:mvvmTitleLabel];
    
    UIButton *mvvmUserInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mvvmUserInfoBtn.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 150)/2,CGRectGetMaxY(mvvmTitleLabel.frame) + 20, 150, 30);
    [mvvmUserInfoBtn setTitle:@"查看个人信息" forState:UIControlStateNormal];
    [mvvmUserInfoBtn addTarget:self action:@selector(mvvmLookUserInfo) forControlEvents:UIControlEventTouchUpInside];
    [mvvmView addSubview:mvvmUserInfoBtn];
    
}

- (void)mvcLookUserInfo:(UIButton *)sender {
    MVCUserViewController *userView = [MVCUserViewController instanceWithUserId:sender.tag];
    [self.navigationController pushViewController:userView animated:YES];
}

- (void)mvcLookSelfUserInfo {
    MVCUserViewController *userView = [[MVCUserViewController alloc]init];;
    [self.navigationController pushViewController:userView animated:YES];
}

- (void)mvpLookUserInfo {
    MVPUserViewController * mvpUserView = [MVPUserViewController instanceWithUserId:123];
    [self.navigationController pushViewController:mvpUserView animated:YES];
}

- (void)mvvmLookUserInfo {
    MVVMUserViewController * mvvmUserView = [MVVMUserViewController instanceWithUserId:123];
    [self.navigationController pushViewController:mvvmUserView animated:YES];
}

@end
